define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'anchor/pf/index' + location.search,
                    add_url: 'anchor/pf/add',
                    edit_url: 'anchor/pf/edit',
                    del_url: 'anchor/pf/del',
                    multi_url: 'anchor/pf/multi',
                    import_url: 'anchor/pf/import',
                    table: 'anchor_pf',
                }
            });

            var table = $("#table");
            var hide_index = Config.hide_index;
            
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'users_id', title: __('Users_id')},
                        {field: 'admin.username', title: __('Admin_id')},
                        {field: 'out_trade_no', title: __('Out_trade_no'), operate: 'LIKE'},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'boxfl_id', title: __('Boxfl_id')},
                        {field: 'boxfl_name', title: __('Boxfl_name'), operate: 'LIKE'},
                        {field: 'num', title: __('Num')},
                        {field: 'pay_coin', title: __('Pay_coin'), operate:'BETWEEN'},
                        {field: 'pay_part', title: __('Pay_part'), operate:'BETWEEN'},
                        {
                          field: 'diaodan',
                          title: __('diaodan'),
                          visible: hide_index,
                          operate: hide_index ? '=' : false,
                          formatter: Table.api.formatter.status,
                          searchList: {1: __("Normal"), 0: __("Hidden")},
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
